/**
 * @file     lengthOfLongestSubstring.ts
 * @brief    [3. 无重复字符的最长子串](https://leetcode.cn/problems/longest-substring-without-repeating-characters/description/)
 * @author   Zhu
 * @date     2023-02-15 03:23
 */

function lengthOfLongestSubstring(s: string): number {
    let i = 0,
        j = 0;
    const set = new Set();
    let max = 0;
    while (j < s.length) {
        if (set.has(s[j])) {
            set.delete(s[i]);
            i++;
        } else {
            set.add(s[j]);
            j++;
        }
        max = Math.max(max, set.size);
    }

    return max;
}
